var choose_file_flag=false;

layui.use(['form',"layer",'upload'], function() {
    var upload=layui.upload;
    //文件上传
    var uploadInst =upload.render({
        elem: '#uploadFile', //绑定元素（上传文件的id）
        url: '/resume-info/sendResume', //上传接口
        method: 'POST',
        auto: false,
        exts: 'pdf',// 设置允许上传的格式
        bindAction: '#uploadBtn', //指向一个按钮触发上传
        size: 102400,//限制文件大小10M
        multiple: false,
        data:{},
        choose:function(obj){
            obj.preview(function(index, file, result){
                if(file.name.length>0) {
                    choose_file_flag=true;
                    $("#filename").text(file.name);
                }
            });
        },
        before: function(obj) {
            obj.preview(function(index, file, result){
                layer.load();
                if(file.name.length>0) {
                    choose_file_flag=true;
                }
            });
            this.data= {
                'userName': $('#userName').val(),
                'userTel': $('#userTel').val(),
                'intentionPost': $('#intentionPost').val()
            };
        },
        done: function(res, file, upload) {//上传完毕回调
            if(res.code==200){
                layer.alert(res.msg,{
                    icon: 1,
                    skin: 'layer-ext-demo',
                    end:function () {
                        location.reload()
                        layer.closeAll('loading');
                    }
                })
            }else{
                layer.alert(res.msg,{
                    icon: 2,
                    skin: 'layer-ext-demo',
                    end:function () {
                        location.reload()
                        layer.closeAll('loading');
                    }
                })
            }
        }
        , error: function() {//请求异常回调
            layer.closeAll('loading');
            layer.alert('上传发生异常，请稍后重试！');
        }
    });
})

var reg_phone = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
//校验
$('#checkBtn').click(function () {
    var loading = layer.load(3, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    var userName=$('#userName').val();
    var userTel=$('#userTel').val();
    var intentionPost=$('#intentionPost').val();
    if(userName==""||userTel==""||intentionPost==""){
        layer.msg("姓名、手机号或意向岗位必填！")
        layer.close(loading)
    }else if(!reg_phone.test(userTel)) {
        layer.msg("手机号格式有误!")
        layer.close(loading)
    }else if(choose_file_flag==false){
        layer.msg("请选择简历附件！")
        layer.close(loading)
    }else {
        layer.close(loading)
        layer.msg("校验成功")
        //数据不可变更
        $('#userTel').attr('disabled','disabled')
        $('#userName').attr('disabled','disabled')
        $('#intentionPost').attr('disabled','disabled')
        $('#uploadFile').addClass('notclick')
        //区域变更
        $('#btnDiv_2').attr('style','margin: 5px')//提交按钮显示
        $('#btnDiv_1').remove()//校验按钮去除
    }
})

//提交
$('#uploadBtn').click(function () {
    var userName=$('#userName').val();
    var userTel=$('#userTel').val();
    if(userName==""||userTel==""||choose_file_flag==false){
        layer.msg("信息不完整，请确认...")
    }else if(!reg_phone.test(userTel)) {
        layer.msg("手机号格式有误!")
    }
})